package m.framework.web.view;

import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import m.framework.utils.LogUtil;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;


/**页面标签拦截器
 * 如果代码写的有错,为防止界面无法限制,这里将所有方法拦截
 * 如果返回的是String,直接显示成错误信息
 * 
 * */
public class TagInterceptor implements MethodInterceptor {
	private static Logger log = LoggerFactory.getLogger(TagInterceptor.class);
	
	public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
		try {
			return methodProxy.invokeSuper(obj, args);
		} catch (Exception ex) {
			log.error("解析标签出错",ex);
			if (method.getReturnType() == String.class) {
				Throwable t = LogUtil.getCause(ex);
				return "<font color='red'>" + t.getMessage() + "</font>";
			}
			throw ex;
		}
	}
}
